{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----------\n",
    "*日期：2022-09-07/week03(周三）\n",
    "*课程：python\n",
    "*记录人：Xiao Lu\n",
    "\n",
    "----------\n",
    "\n",
    "# 本周学习内容\n",
    "\n",
    "> 1.变量\n",
    ">> 1.变量的定义与声明\n",
    ">> 2.变量名的一般规则\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "> 2.编程的控制流\n",
    ">> 1.条件判断\n",
    ">>2.循环遍历\n",
    "\n",
    "\n",
    "https://www.cnblogs.com/xuzhichao/p/11407192.html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 变量学"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_ID=\"2200000001\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网三_01_ID\n"
     ]
    }
   ],
   "source": [
    "print('网三_01_ID')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2200000001'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_01_ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_name=\"小白\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小白'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_01_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_ID=\"230000001\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'230000001'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_01_ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小白 小白\n",
      "Alex 小白\n"
     ]
    }
   ],
   "source": [
    "网三_01_name=\"小白\"\n",
    "\n",
    "网三_02_name=网三_01_name\n",
    "\n",
    "print(网三_01_name,网三_02_name)\n",
    "\n",
    "网三_01_name=\"Alex\"\n",
    "\n",
    "print(网三_01_name,网三_02_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网三_01_ID\n"
     ]
    }
   ],
   "source": [
    "print('网三_01_ID')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.条件判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课本案例 P18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Recover,then rest.\n"
     ]
    }
   ],
   "source": [
    "# 变量today需要先赋值\n",
    "today=\"Sunday\"\n",
    "condition =\"Headache\"\n",
    "\n",
    "\n",
    "if today ==\"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today ==\"Sunday\":\n",
    "    if condition ==\"Headache\":\n",
    "        print(\"Recover,then rest.\")\n",
    "    else:\n",
    "         print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work,work,work.\")\n",
    "    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#练习题：判断今天是否有python课（time.localtime()),然后如果今天有python课，再判断现在是否python课ing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=7, tm_hour=20, tm_min=13, tm_sec=26, tm_wday=2, tm_yday=250, tm_isdst=0)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "21\n",
      "0\n",
      "今天有Python课，好开心呀！\n",
      "今天的Python课很不错\n"
     ]
    }
   ],
   "source": [
    "#创建week_day变量，time_hour变量，time_min变量\n",
    "week_day = time.localtime().tm_wday\n",
    "print(week_day)\n",
    "\n",
    "time_hour= time.localtime().tm_hour\n",
    "print(time_hour)\n",
    "\n",
    "time_min = time.localtime().tm_min\n",
    "print(time_min)\n",
    "\n",
    "if week_day ==2:\n",
    "    print(\"今天有Python课，好开心呀！\")\n",
    "    if time_hour ==19:\n",
    "        print(\"Python课ing,刚上课\")\n",
    "    elif time_hour ==18 and time_min > 44:\n",
    "         print(\"Python课ing，现在在第二节课\")\n",
    "    elif time_hour == 20 and time_min < 51:\n",
    "         print(\"Python课，第三节课\")\n",
    "    elif time_hour<18:\n",
    "         print(\"期待今天的课\")\n",
    "    else:\n",
    "         print(\"今天的Python课很不错\")\n",
    "else:\n",
    "     print(\"怎么还没到星期三呢，唉，等的着急\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in module time:\n",
      "\n",
      "NAME\n",
      "    time - This module provides various functions to manipulate time values.\n",
      "\n",
      "DESCRIPTION\n",
      "    There are two standard representations of time.  One is the number\n",
      "    of seconds since the Epoch, in UTC (a.k.a. GMT).  It may be an integer\n",
      "    or a floating point number (to represent fractions of seconds).\n",
      "    The Epoch is system-defined; on Unix, it is generally January 1st, 1970.\n",
      "    The actual value can be retrieved by calling gmtime(0).\n",
      "    \n",
      "    The other representation is a tuple of 9 integers giving local time.\n",
      "    The tuple items are:\n",
      "      year (including century, e.g. 1998)\n",
      "      month (1-12)\n",
      "      day (1-31)\n",
      "      hours (0-23)\n",
      "      minutes (0-59)\n",
      "      seconds (0-59)\n",
      "      weekday (0-6, Monday is 0)\n",
      "      Julian day (day in the year, 1-366)\n",
      "      DST (Daylight Savings Time) flag (-1, 0 or 1)\n",
      "    If the DST flag is 0, the time is given in the regular time zone;\n",
      "    if it is 1, the time is given in the DST time zone;\n",
      "    if it is -1, mktime() should guess based on the date and time.\n",
      "\n",
      "CLASSES\n",
      "    builtins.tuple(builtins.object)\n",
      "        struct_time\n",
      "    \n",
      "    class struct_time(builtins.tuple)\n",
      "     |  struct_time(iterable=(), /)\n",
      "     |  \n",
      "     |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      "     |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      "     |  sequence of 9 integers.\n",
      "     |  \n",
      "     |  Note that several fields' values are not the same as those defined by\n",
      "     |  the C language standard for struct tm.  For example, the value of the\n",
      "     |  field tm_year is the actual year, not year - 1900.  See individual\n",
      "     |  fields' descriptions for details.\n",
      "     |  \n",
      "     |  Method resolution order:\n",
      "     |      struct_time\n",
      "     |      builtins.tuple\n",
      "     |      builtins.object\n",
      "     |  \n",
      "     |  Methods defined here:\n",
      "     |  \n",
      "     |  __reduce__(...)\n",
      "     |      Helper for pickle.\n",
      "     |  \n",
      "     |  __repr__(self, /)\n",
      "     |      Return repr(self).\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Static methods defined here:\n",
      "     |  \n",
      "     |  __new__(*args, **kwargs) from builtins.type\n",
      "     |      Create and return a new object.  See help(type) for accurate signature.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data descriptors defined here:\n",
      "     |  \n",
      "     |  tm_gmtoff\n",
      "     |      offset from UTC in seconds\n",
      "     |  \n",
      "     |  tm_hour\n",
      "     |      hours, range [0, 23]\n",
      "     |  \n",
      "     |  tm_isdst\n",
      "     |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      "     |  \n",
      "     |  tm_mday\n",
      "     |      day of month, range [1, 31]\n",
      "     |  \n",
      "     |  tm_min\n",
      "     |      minutes, range [0, 59]\n",
      "     |  \n",
      "     |  tm_mon\n",
      "     |      month of year, range [1, 12]\n",
      "     |  \n",
      "     |  tm_sec\n",
      "     |      seconds, range [0, 61])\n",
      "     |  \n",
      "     |  tm_wday\n",
      "     |      day of week, range [0, 6], Monday is 0\n",
      "     |  \n",
      "     |  tm_yday\n",
      "     |      day of year, range [1, 366]\n",
      "     |  \n",
      "     |  tm_year\n",
      "     |      year, for example, 1993\n",
      "     |  \n",
      "     |  tm_zone\n",
      "     |      abbreviation of timezone name\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data and other attributes defined here:\n",
      "     |  \n",
      "     |  n_fields = 11\n",
      "     |  \n",
      "     |  n_sequence_fields = 9\n",
      "     |  \n",
      "     |  n_unnamed_fields = 0\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from builtins.tuple:\n",
      "     |  \n",
      "     |  __add__(self, value, /)\n",
      "     |      Return self+value.\n",
      "     |  \n",
      "     |  __contains__(self, key, /)\n",
      "     |      Return key in self.\n",
      "     |  \n",
      "     |  __eq__(self, value, /)\n",
      "     |      Return self==value.\n",
      "     |  \n",
      "     |  __ge__(self, value, /)\n",
      "     |      Return self>=value.\n",
      "     |  \n",
      "     |  __getattribute__(self, name, /)\n",
      "     |      Return getattr(self, name).\n",
      "     |  \n",
      "     |  __getitem__(self, key, /)\n",
      "     |      Return self[key].\n",
      "     |  \n",
      "     |  __getnewargs__(self, /)\n",
      "     |  \n",
      "     |  __gt__(self, value, /)\n",
      "     |      Return self>value.\n",
      "     |  \n",
      "     |  __hash__(self, /)\n",
      "     |      Return hash(self).\n",
      "     |  \n",
      "     |  __iter__(self, /)\n",
      "     |      Implement iter(self).\n",
      "     |  \n",
      "     |  __le__(self, value, /)\n",
      "     |      Return self<=value.\n",
      "     |  \n",
      "     |  __len__(self, /)\n",
      "     |      Return len(self).\n",
      "     |  \n",
      "     |  __lt__(self, value, /)\n",
      "     |      Return self<value.\n",
      "     |  \n",
      "     |  __mul__(self, value, /)\n",
      "     |      Return self*value.\n",
      "     |  \n",
      "     |  __ne__(self, value, /)\n",
      "     |      Return self!=value.\n",
      "     |  \n",
      "     |  __rmul__(self, value, /)\n",
      "     |      Return value*self.\n",
      "     |  \n",
      "     |  count(self, value, /)\n",
      "     |      Return number of occurrences of value.\n",
      "     |  \n",
      "     |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      "     |      Return first index of value.\n",
      "     |      \n",
      "     |      Raises ValueError if the value is not present.\n",
      "\n",
      "FUNCTIONS\n",
      "    asctime(...)\n",
      "        asctime([tuple]) -> string\n",
      "        \n",
      "        Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.\n",
      "        When the time tuple is not present, current time as returned by localtime()\n",
      "        is used.\n",
      "    \n",
      "    clock(...)\n",
      "        clock() -> floating point number\n",
      "        \n",
      "        Return the CPU time or real time since the start of the process or since\n",
      "        the first call to clock().  This has as much precision as the system\n",
      "        records.\n",
      "    \n",
      "    ctime(...)\n",
      "        ctime(seconds) -> string\n",
      "        \n",
      "        Convert a time in seconds since the Epoch to a string in local time.\n",
      "        This is equivalent to asctime(localtime(seconds)). When the time tuple is\n",
      "        not present, current time as returned by localtime() is used.\n",
      "    \n",
      "    get_clock_info(...)\n",
      "        get_clock_info(name: str) -> dict\n",
      "        \n",
      "        Get information of the specified clock.\n",
      "    \n",
      "    gmtime(...)\n",
      "        gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,\n",
      "                               tm_sec, tm_wday, tm_yday, tm_isdst)\n",
      "        \n",
      "        Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.\n",
      "        GMT).  When 'seconds' is not passed in, convert the current time instead.\n",
      "        \n",
      "        If the platform supports the tm_gmtoff and tm_zone, they are available as\n",
      "        attributes only.\n",
      "    \n",
      "    localtime(...)\n",
      "        localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,\n",
      "                                  tm_sec,tm_wday,tm_yday,tm_isdst)\n",
      "        \n",
      "        Convert seconds since the Epoch to a time tuple expressing local time.\n",
      "        When 'seconds' is not passed in, convert the current time instead.\n",
      "    \n",
      "    mktime(...)\n",
      "        mktime(tuple) -> floating point number\n",
      "        \n",
      "        Convert a time tuple in local time to seconds since the Epoch.\n",
      "        Note that mktime(gmtime(0)) will not generally return zero for most\n",
      "        time zones; instead the returned value will either be equal to that\n",
      "        of the timezone or altzone attributes on the time module.\n",
      "    \n",
      "    monotonic(...)\n",
      "        monotonic() -> float\n",
      "        \n",
      "        Monotonic clock, cannot go backward.\n",
      "    \n",
      "    monotonic_ns(...)\n",
      "        monotonic_ns() -> int\n",
      "        \n",
      "        Monotonic clock, cannot go backward, as nanoseconds.\n",
      "    \n",
      "    perf_counter(...)\n",
      "        perf_counter() -> float\n",
      "        \n",
      "        Performance counter for benchmarking.\n",
      "    \n",
      "    perf_counter_ns(...)\n",
      "        perf_counter_ns() -> int\n",
      "        \n",
      "        Performance counter for benchmarking as nanoseconds.\n",
      "    \n",
      "    process_time(...)\n",
      "        process_time() -> float\n",
      "        \n",
      "        Process time for profiling: sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    process_time_ns(...)\n",
      "        process_time() -> int\n",
      "        \n",
      "        Process time for profiling as nanoseconds:\n",
      "        sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    sleep(...)\n",
      "        sleep(seconds)\n",
      "        \n",
      "        Delay execution for a given number of seconds.  The argument may be\n",
      "        a floating point number for subsecond precision.\n",
      "    \n",
      "    strftime(...)\n",
      "        strftime(format[, tuple]) -> string\n",
      "        \n",
      "        Convert a time tuple to a string according to a format specification.\n",
      "        See the library reference manual for formatting codes. When the time tuple\n",
      "        is not present, current time as returned by localtime() is used.\n",
      "        \n",
      "        Commonly used format codes:\n",
      "        \n",
      "        %Y  Year with century as a decimal number.\n",
      "        %m  Month as a decimal number [01,12].\n",
      "        %d  Day of the month as a decimal number [01,31].\n",
      "        %H  Hour (24-hour clock) as a decimal number [00,23].\n",
      "        %M  Minute as a decimal number [00,59].\n",
      "        %S  Second as a decimal number [00,61].\n",
      "        %z  Time zone offset from UTC.\n",
      "        %a  Locale's abbreviated weekday name.\n",
      "        %A  Locale's full weekday name.\n",
      "        %b  Locale's abbreviated month name.\n",
      "        %B  Locale's full month name.\n",
      "        %c  Locale's appropriate date and time representation.\n",
      "        %I  Hour (12-hour clock) as a decimal number [01,12].\n",
      "        %p  Locale's equivalent of either AM or PM.\n",
      "        \n",
      "        Other codes may be available on your platform.  See documentation for\n",
      "        the C library strftime function.\n",
      "    \n",
      "    strptime(...)\n",
      "        strptime(string, format) -> struct_time\n",
      "        \n",
      "        Parse a string to a time tuple according to a format specification.\n",
      "        See the library reference manual for formatting codes (same as\n",
      "        strftime()).\n",
      "        \n",
      "        Commonly used format codes:\n",
      "        \n",
      "        %Y  Year with century as a decimal number.\n",
      "        %m  Month as a decimal number [01,12].\n",
      "        %d  Day of the month as a decimal number [01,31].\n",
      "        %H  Hour (24-hour clock) as a decimal number [00,23].\n",
      "        %M  Minute as a decimal number [00,59].\n",
      "        %S  Second as a decimal number [00,61].\n",
      "        %z  Time zone offset from UTC.\n",
      "        %a  Locale's abbreviated weekday name.\n",
      "        %A  Locale's full weekday name.\n",
      "        %b  Locale's abbreviated month name.\n",
      "        %B  Locale's full month name.\n",
      "        %c  Locale's appropriate date and time representation.\n",
      "        %I  Hour (12-hour clock) as a decimal number [01,12].\n",
      "        %p  Locale's equivalent of either AM or PM.\n",
      "        \n",
      "        Other codes may be available on your platform.  See documentation for\n",
      "        the C library strftime function.\n",
      "    \n",
      "    thread_time(...)\n",
      "        thread_time() -> float\n",
      "        \n",
      "        Thread time for profiling: sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    thread_time_ns(...)\n",
      "        thread_time() -> int\n",
      "        \n",
      "        Thread time for profiling as nanoseconds:\n",
      "        sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    time(...)\n",
      "        time() -> floating point number\n",
      "        \n",
      "        Return the current time in seconds since the Epoch.\n",
      "        Fractions of a second may be present if the system clock provides them.\n",
      "    \n",
      "    time_ns(...)\n",
      "        time_ns() -> int\n",
      "        \n",
      "        Return the current time in nanoseconds since the Epoch.\n",
      "\n",
      "DATA\n",
      "    altzone = -32400\n",
      "    daylight = 0\n",
      "    timezone = -28800\n",
      "    tzname = ('ÖÐ¹ú±ê×¼Ê±¼ä', 'ÖÐ¹úÏÄÁîÊ±')\n",
      "\n",
      "FILE\n",
      "    (built-in)\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# help(time)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 循环遍历\n",
    "> 1.for循环\n",
    "> 2.range()方法\n",
    "\n",
    " i是变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "#用例1\n",
    "for i in [1,2,3]:\n",
    "    print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "#用例2\n",
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "#range 可以创建数组\n",
    "#用例3 默认从0开始的（start),默认步长为1\n",
    "for num in range(5):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.1关于range"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "#用例3 扩展1.默认从0 开始的（start),但这个可以设置起点 起点是1\n",
    "for num in range(1,5):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "3\n",
      "5\n",
      "7\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "#用例3 扩展2.起点为1 终点为10 步长step 2\n",
    "for num in range(1,10,2):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "8\n",
      "6\n",
      "4\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "#用例3 扩展3.起点为10 终点为1 步长step -2\n",
    "for num in range(10,1,-2):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "docs.python.org/3/library/stdypes.html#range"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "###课后作业：P35项目 和P43"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# p35 作业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this minute seems a little odd.\n",
      "this minute seems a little odd.\n",
      "this minute seems a little odd.\n",
      "not an odd minute.\n",
      "this minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35,\n",
    "         37, 39, 41, 43, 45, 51, 53, 55, 57, 59 ]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_minute = datetime.today().minute\n",
    "    if right_this_minute in odds:\n",
    "        print(\"this minute seems a little odd.\")\n",
    "    else:\n",
    "        print(\"not an odd minute.\")\n",
    "    wait_time = random.randint(1,60)\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# p43 作业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 bottles of beer on the wall.\n",
      "99 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "98 bottles of beer on teh wall.\n",
      "\n",
      "98 bottles of beer on the wall.\n",
      "98 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "97 bottles of beer on teh wall.\n",
      "\n",
      "97 bottles of beer on the wall.\n",
      "97 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "96 bottles of beer on teh wall.\n",
      "\n",
      "96 bottles of beer on the wall.\n",
      "96 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "95 bottles of beer on teh wall.\n",
      "\n",
      "95 bottles of beer on the wall.\n",
      "95 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "94 bottles of beer on teh wall.\n",
      "\n",
      "94 bottles of beer on the wall.\n",
      "94 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "93 bottles of beer on teh wall.\n",
      "\n",
      "93 bottles of beer on the wall.\n",
      "93 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "92 bottles of beer on teh wall.\n",
      "\n",
      "92 bottles of beer on the wall.\n",
      "92 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "91 bottles of beer on teh wall.\n",
      "\n",
      "91 bottles of beer on the wall.\n",
      "91 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "90 bottles of beer on teh wall.\n",
      "\n",
      "90 bottles of beer on the wall.\n",
      "90 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "89 bottles of beer on teh wall.\n",
      "\n",
      "89 bottles of beer on the wall.\n",
      "89 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "88 bottles of beer on teh wall.\n",
      "\n",
      "88 bottles of beer on the wall.\n",
      "88 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "87 bottles of beer on teh wall.\n",
      "\n",
      "87 bottles of beer on the wall.\n",
      "87 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "86 bottles of beer on teh wall.\n",
      "\n",
      "86 bottles of beer on the wall.\n",
      "86 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "85 bottles of beer on teh wall.\n",
      "\n",
      "85 bottles of beer on the wall.\n",
      "85 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "84 bottles of beer on teh wall.\n",
      "\n",
      "84 bottles of beer on the wall.\n",
      "84 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "83 bottles of beer on teh wall.\n",
      "\n",
      "83 bottles of beer on the wall.\n",
      "83 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "82 bottles of beer on teh wall.\n",
      "\n",
      "82 bottles of beer on the wall.\n",
      "82 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "81 bottles of beer on teh wall.\n",
      "\n",
      "81 bottles of beer on the wall.\n",
      "81 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "80 bottles of beer on teh wall.\n",
      "\n",
      "80 bottles of beer on the wall.\n",
      "80 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "79 bottles of beer on teh wall.\n",
      "\n",
      "79 bottles of beer on the wall.\n",
      "79 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "78 bottles of beer on teh wall.\n",
      "\n",
      "78 bottles of beer on the wall.\n",
      "78 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "77 bottles of beer on teh wall.\n",
      "\n",
      "77 bottles of beer on the wall.\n",
      "77 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "76 bottles of beer on teh wall.\n",
      "\n",
      "76 bottles of beer on the wall.\n",
      "76 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "75 bottles of beer on teh wall.\n",
      "\n",
      "75 bottles of beer on the wall.\n",
      "75 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "74 bottles of beer on teh wall.\n",
      "\n",
      "74 bottles of beer on the wall.\n",
      "74 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "73 bottles of beer on teh wall.\n",
      "\n",
      "73 bottles of beer on the wall.\n",
      "73 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "72 bottles of beer on teh wall.\n",
      "\n",
      "72 bottles of beer on the wall.\n",
      "72 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "71 bottles of beer on teh wall.\n",
      "\n",
      "71 bottles of beer on the wall.\n",
      "71 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "70 bottles of beer on teh wall.\n",
      "\n",
      "70 bottles of beer on the wall.\n",
      "70 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "69 bottles of beer on teh wall.\n",
      "\n",
      "69 bottles of beer on the wall.\n",
      "69 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "68 bottles of beer on teh wall.\n",
      "\n",
      "68 bottles of beer on the wall.\n",
      "68 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "67 bottles of beer on teh wall.\n",
      "\n",
      "67 bottles of beer on the wall.\n",
      "67 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "66 bottles of beer on teh wall.\n",
      "\n",
      "66 bottles of beer on the wall.\n",
      "66 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "65 bottles of beer on teh wall.\n",
      "\n",
      "65 bottles of beer on the wall.\n",
      "65 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "64 bottles of beer on teh wall.\n",
      "\n",
      "64 bottles of beer on the wall.\n",
      "64 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "63 bottles of beer on teh wall.\n",
      "\n",
      "63 bottles of beer on the wall.\n",
      "63 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "62 bottles of beer on teh wall.\n",
      "\n",
      "62 bottles of beer on the wall.\n",
      "62 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "61 bottles of beer on teh wall.\n",
      "\n",
      "61 bottles of beer on the wall.\n",
      "61 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "60 bottles of beer on teh wall.\n",
      "\n",
      "60 bottles of beer on the wall.\n",
      "60 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "59 bottles of beer on teh wall.\n",
      "\n",
      "59 bottles of beer on the wall.\n",
      "59 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "58 bottles of beer on teh wall.\n",
      "\n",
      "58 bottles of beer on the wall.\n",
      "58 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "57 bottles of beer on teh wall.\n",
      "\n",
      "57 bottles of beer on the wall.\n",
      "57 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "56 bottles of beer on teh wall.\n",
      "\n",
      "56 bottles of beer on the wall.\n",
      "56 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "55 bottles of beer on teh wall.\n",
      "\n",
      "55 bottles of beer on the wall.\n",
      "55 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "54 bottles of beer on teh wall.\n",
      "\n",
      "54 bottles of beer on the wall.\n",
      "54 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "53 bottles of beer on teh wall.\n",
      "\n",
      "53 bottles of beer on the wall.\n",
      "53 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "52 bottles of beer on teh wall.\n",
      "\n",
      "52 bottles of beer on the wall.\n",
      "52 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "51 bottles of beer on teh wall.\n",
      "\n",
      "51 bottles of beer on the wall.\n",
      "51 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "50 bottles of beer on teh wall.\n",
      "\n",
      "50 bottles of beer on the wall.\n",
      "50 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "49 bottles of beer on teh wall.\n",
      "\n",
      "49 bottles of beer on the wall.\n",
      "49 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "48 bottles of beer on teh wall.\n",
      "\n",
      "48 bottles of beer on the wall.\n",
      "48 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "47 bottles of beer on teh wall.\n",
      "\n",
      "47 bottles of beer on the wall.\n",
      "47 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "46 bottles of beer on teh wall.\n",
      "\n",
      "46 bottles of beer on the wall.\n",
      "46 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "45 bottles of beer on teh wall.\n",
      "\n",
      "45 bottles of beer on the wall.\n",
      "45 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "44 bottles of beer on teh wall.\n",
      "\n",
      "44 bottles of beer on the wall.\n",
      "44 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "43 bottles of beer on teh wall.\n",
      "\n",
      "43 bottles of beer on the wall.\n",
      "43 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "42 bottles of beer on teh wall.\n",
      "\n",
      "42 bottles of beer on the wall.\n",
      "42 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "41 bottles of beer on teh wall.\n",
      "\n",
      "41 bottles of beer on the wall.\n",
      "41 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "40 bottles of beer on teh wall.\n",
      "\n",
      "40 bottles of beer on the wall.\n",
      "40 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "39 bottles of beer on teh wall.\n",
      "\n",
      "39 bottles of beer on the wall.\n",
      "39 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "38 bottles of beer on teh wall.\n",
      "\n",
      "38 bottles of beer on the wall.\n",
      "38 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "37 bottles of beer on teh wall.\n",
      "\n",
      "37 bottles of beer on the wall.\n",
      "37 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "36 bottles of beer on teh wall.\n",
      "\n",
      "36 bottles of beer on the wall.\n",
      "36 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "35 bottles of beer on teh wall.\n",
      "\n",
      "35 bottles of beer on the wall.\n",
      "35 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "34 bottles of beer on teh wall.\n",
      "\n",
      "34 bottles of beer on the wall.\n",
      "34 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "33 bottles of beer on teh wall.\n",
      "\n",
      "33 bottles of beer on the wall.\n",
      "33 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "32 bottles of beer on teh wall.\n",
      "\n",
      "32 bottles of beer on the wall.\n",
      "32 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "31 bottles of beer on teh wall.\n",
      "\n",
      "31 bottles of beer on the wall.\n",
      "31 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "30 bottles of beer on teh wall.\n",
      "\n",
      "30 bottles of beer on the wall.\n",
      "30 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "29 bottles of beer on teh wall.\n",
      "\n",
      "29 bottles of beer on the wall.\n",
      "29 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "28 bottles of beer on teh wall.\n",
      "\n",
      "28 bottles of beer on the wall.\n",
      "28 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "27 bottles of beer on teh wall.\n",
      "\n",
      "27 bottles of beer on the wall.\n",
      "27 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "26 bottles of beer on teh wall.\n",
      "\n",
      "26 bottles of beer on the wall.\n",
      "26 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "25 bottles of beer on teh wall.\n",
      "\n",
      "25 bottles of beer on the wall.\n",
      "25 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "24 bottles of beer on teh wall.\n",
      "\n",
      "24 bottles of beer on the wall.\n",
      "24 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "23 bottles of beer on teh wall.\n",
      "\n",
      "23 bottles of beer on the wall.\n",
      "23 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "22 bottles of beer on teh wall.\n",
      "\n",
      "22 bottles of beer on the wall.\n",
      "22 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "21 bottles of beer on teh wall.\n",
      "\n",
      "21 bottles of beer on the wall.\n",
      "21 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "20 bottles of beer on teh wall.\n",
      "\n",
      "20 bottles of beer on the wall.\n",
      "20 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "19 bottles of beer on teh wall.\n",
      "\n",
      "19 bottles of beer on the wall.\n",
      "19 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "18 bottles of beer on teh wall.\n",
      "\n",
      "18 bottles of beer on the wall.\n",
      "18 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "17 bottles of beer on teh wall.\n",
      "\n",
      "17 bottles of beer on the wall.\n",
      "17 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "16 bottles of beer on teh wall.\n",
      "\n",
      "16 bottles of beer on the wall.\n",
      "16 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "15 bottles of beer on teh wall.\n",
      "\n",
      "15 bottles of beer on the wall.\n",
      "15 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "14 bottles of beer on teh wall.\n",
      "\n",
      "14 bottles of beer on the wall.\n",
      "14 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "13 bottles of beer on teh wall.\n",
      "\n",
      "13 bottles of beer on the wall.\n",
      "13 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "12 bottles of beer on teh wall.\n",
      "\n",
      "12 bottles of beer on the wall.\n",
      "12 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "11 bottles of beer on teh wall.\n",
      "\n",
      "11 bottles of beer on the wall.\n",
      "11 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "10 bottles of beer on teh wall.\n",
      "\n",
      "10 bottles of beer on the wall.\n",
      "10 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "9 bottles of beer on teh wall.\n",
      "\n",
      "9 bottles of beer on the wall.\n",
      "9 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "8 bottles of beer on teh wall.\n",
      "\n",
      "8 bottles of beer on the wall.\n",
      "8 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "7 bottles of beer on teh wall.\n",
      "\n",
      "7 bottles of beer on the wall.\n",
      "7 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "6 bottles of beer on teh wall.\n",
      "\n",
      "6 bottles of beer on the wall.\n",
      "6 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "5 bottles of beer on teh wall.\n",
      "\n",
      "5 bottles of beer on the wall.\n",
      "5 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "4 bottles of beer on teh wall.\n",
      "\n",
      "4 bottles of beer on the wall.\n",
      "4 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "3 bottles of beer on teh wall.\n",
      "\n",
      "3 bottles of beer on the wall.\n",
      "3 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "2 bottles of beer on teh wall.\n",
      "\n",
      "2 bottles of beer on the wall.\n",
      "2 bottles of beer\n",
      "take one down\n",
      "pass it around.\n",
      "1 bottle of beer on teh wall.\n",
      "\n",
      "1 bottle of beer on the wall.\n",
      "1 bottle of beer\n",
      "take one down\n",
      "pass it around.\n",
      "no more bottle of beer on the wall.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "word = \"bottles\" # 将值赋予变量\n",
    "\n",
    "for beer_num in range(99,0,-1):  #起点为99  终点为 0   步长step  -1\n",
    "    print(beer_num, word, \"of beer on the wall.\")\n",
    "    print(beer_num, word, \"of beer\") # 墙上少一瓶啤酒\n",
    "    print(\"take one down\")\n",
    "    print(\"pass it around.\") # 输出四行歌词\n",
    "    if beer_num == 1:  # 如果墙上最后一瓶酒被拿走时（条件判断）\n",
    "        print(\"no more bottle of beer on the wall.\")\n",
    "    else:  # 如果墙上有一瓶以上的酒时（条件判断）\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1:\n",
    "            word = \"bottle\" # 最后一瓶酒\n",
    "        print(new_num, word, \"of beer on teh wall.\")\n",
    "    print()# 终止程序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
